import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LYDatePicker extends StatefulWidget {
  const LYDatePicker({super.key});

  @override
  State<LYDatePicker> createState() => _LYDatePickerState();
}

class _LYDatePickerState extends State<LYDatePicker> {
  final int currentYear = DateTime.now().year;
  final months = [
    "一月",
    "二月",
    "三月",
    "四月",
    "五月",
    "六月",
    "七月",
    "八月",
    "九月",
    "十月",
    "十一月",
    "十二月"
  ];
  final days = [
    '初一',
    '初二',
    '初三',
    '初四',
    '初五',
    '初六',
    '初七',
    '初八',
    '初九',
    '初十',
    '十一',
    '十二',
    '十三',
    '十四',
    '十五',
    '十六',
    '十七',
    '十八',
    '十九',
    '二十',
    '廿一',
    '廿二',
    '廿三',
    '廿四',
    '廿五',
    '廿六',
    '廿七',
    '廿八',
    '廿九',
    '三十',
  ];
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 300,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [_makeYearPicker(), _makeMonthPicker(), _makeDayPicker()],
      ),
    );
  }

  Widget _makeYearPicker() {
    return Expanded(
      child: CupertinoPicker.builder(
        itemExtent: 50,
        onSelectedItemChanged: (index) {},
        itemBuilder: (ctx, index) {
          final title = "${currentYear - index}";
          return Container(
            alignment: Alignment.center,
            child: Text(
              title,
              style: const TextStyle(fontSize: 15, color: Colors.black),
            ),
          );
        },
        childCount: 100,
      ),
    );
  }

  Widget _makeMonthPicker() {
    return Expanded(
      child: CupertinoPicker.builder(
        itemExtent: 50,
        onSelectedItemChanged: (index) {},
        itemBuilder: (ctx, index) {
          final title = months[index];
          return Container(
            alignment: Alignment.center,
            child: Text(
              title,
              style: const TextStyle(fontSize: 15, color: Colors.black),
            ),
          );
        },
        childCount: months.length,
      ),
    );
  }

  Widget _makeDayPicker() {
    return Expanded(
      child: CupertinoPicker.builder(
        itemExtent: 50,
        onSelectedItemChanged: (index) {},
        itemBuilder: (ctx, index) {
          final title = days[index];
          return Container(
            alignment: Alignment.center,
            child: Text(
              title,
              style: const TextStyle(fontSize: 15, color: Colors.black),
            ),
          );
        },
        childCount: days.length,
      ),
    );
  }
}
